//
//  ZPowerCell.m
//  WeClubs
//
//  Created by Zed Link on 4/5/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "ZPowerCell.h"
#import "UIImage+ZUtilities.h"

@interface ZPowerCell ()

@property (weak, nonatomic) IBOutlet UIButton *nameBtn;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;

@end

@implementation ZPowerCell

- (void)zSetupCell
{
    [super zSetupCell];
    [self.contentView setBackgroundColor:NAVBAR_BG_COLOR];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [self.nameBtn zCornerDeal:14];
    [self.nameBtn addTarget:self action:@selector(nameBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.nameBtn setTitleColor:FONT_THIRD_COLOR forState:UIControlStateNormal];
    [self.nameBtn setBackgroundImage:[UIImage zImageWithColor:SEPARATOR_BG_COLOR size:CGSizeMake(72, 28) andRadius:16] forState:UIControlStateNormal];
    [self.nameBtn setTitleColor:NAVBAR_BG_COLOR forState:UIControlStateSelected];
    [self.nameBtn setBackgroundImage:[UIImage zImageWithColor:HIGHTLIGHT_COLOR size:CGSizeMake(72, 28) andRadius:16] forState:UIControlStateSelected];
}

- (void)nameBtnAction:(UIButton *)sender
{
    self.state = !self.state;
    
    if ([self.delegate respondsToSelector:@selector(powerCell:selectPower:withDescription:)]) {
        [self.delegate powerCell:self selectPower:sender.selected withDescription:sender.currentTitle];
    }
}

- (void)setPowerName:(NSString *)name andDescription:(NSString *)desc
{
    [self.nameBtn setTitle:name forState:UIControlStateNormal];
    [self.descLabel setText:desc];
}

- (void)setState:(ZPowerChoseState)state
{
    _state = state;
    
    switch (state) {
        case ZPowerChoseStateNormal:
        {
            self.nameBtn.selected = NO;
        }
            break;
        case ZPowerChoseStateSelected:
        {
            self.nameBtn.selected = YES;
        }
            break;
        default:
            break;
    }
}

@end
